package com.boot.web.controller;

import java.util.Map;

import com.boot.web.entity.Role;
import com.boot.web.service.RoleService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.boot.communal.paging.InitPaging;
import com.boot.communal.response.ResponseServer;

/**
 * 系统角色信息控制器
 * @author 【zhouJie】
 * @date 2019-12-05 17:31:35
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @PostMapping("/save")
    public ResponseServer save(Role role) {
        return ResponseServer.success("添加成功", roleService.saveRole(role));
    }

    @PutMapping("/update")
    public ResponseServer update(Role role) {
        return ResponseServer.success("修改成功", roleService.updateRole(role));
    }

    @DeleteMapping("/delete/{id}")
    public ResponseServer delete(@PathVariable Integer id) {
        return ResponseServer.success("系统角色信息删除成功", roleService.delete(id));
    }

    @DeleteMapping("/batchDelete/{ids}")
    public ResponseServer batchDelete(@PathVariable Integer[] ids) {
        return ResponseServer.success("批量删除成功", roleService.batchDelete(ids));
    }

    @GetMapping("/getPageList")
    public ResponseServer getPageList(@RequestParam Map<String, Object> params) {
        InitPaging.init(params);
        return ResponseServer.success(new PageInfo(roleService.getRoleVoPageList(params)));
    }

    @GetMapping("/getAll")
    public ResponseServer getAll() {
        return ResponseServer.success(roleService.getAll());
    }

    @GetMapping("/getById/{id}")
    public ResponseServer getById(@PathVariable Integer id) {
        return ResponseServer.success(roleService.getById(id));
    }

    @PostMapping("/setDefault")
    public ResponseServer setDefaultRole(Role role) {
        return ResponseServer.success("设置成功", roleService.setDefaultRole(role));
    }

    @PostMapping("/updateRolePower")
    public ResponseServer updateRolePower(@RequestParam("roleId") Integer roleId, @RequestParam("powerIds") Integer[] powerIds) {
        return ResponseServer.success("修改成功", roleService.updateRolePower(roleId, powerIds));
    }

}
